﻿
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace Synergy
{
    public static class SqlSugarHelp
    {

        public static SqlSugarScope scope = new SqlSugarScope(new ConnectionConfig()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["actived"].ConnectionString,//连接符字串
                                                                                                  //ConnectionString = ConfigurationManager.ConnectionStrings["pro"].ConnectionString,//连接符字串
            DbType = DbType.SqlServer,//数据库类型
            IsAutoCloseConnection = true //不设成true要手动close
        },
           db =>
           {
               //db.Aop.OnLogExecuting = (sql, pars) =>
               //{
               //    Logger.Info(sql);//输出sql
               //    Logger.Info(string.Join(",", pars?.Select(it => it.ParameterName + ":" + it.Value)));//参数
               //                                                                                         //int i =  SQLscope.Insertable(new SQLRecord() { 操作人 = salesMan.SalesManName, 操作时间 = DateTime.Now.ToString(), sql = sql, para = string.Join(",", pars?.Select(it => it.ParameterName + ":" + it.Value)) }).ExecuteCommand();
               //};
               //db.Aop.OnError = (exp) =>//SQL报错
               //{
               //    Logger.Error(exp.Sql);
               //};
               //db.Aop.OnLogExecuted = (sql, p) =>
               //{
               //    //执行时间超过1秒
               //    if (db.Ado.SqlExecutionTime.TotalSeconds > 1)
               //    {
               //        //代码CS文件名
               //        var fileName = db.Ado.SqlStackTrace.FirstFileName;
               //        //代码行数
               //        var fileLine = db.Ado.SqlStackTrace.FirstLine;
               //        //方法名
               //        var FirstMethodName = db.Ado.SqlStackTrace.FirstMethodName;
               //        Logger.Warn("执行超过1s的sql【" + sql + "】代码CS文件名【" + fileName + "】代码行数【" + fileLine + "】");
               //        //db.Ado.SqlStackTrace.MyStackTraceList[1].xxx 获取上层方法的信息
               //    }
               //};
           }

           );
    }
}
